Skip to content

Fix Tizen linking flags used during ILCompiler build#129844

Open
gbalykov wants to merge 1 commit into
dotnet:mainfrom
gbalykov:fix-tizen-link-args
Open

Fix Tizen linking flags used during ILCompiler build#129844
gbalykov wants to merge 1 commit into
dotnet:mainfrom
gbalykov:fix-tizen-link-args

Conversation

@gbalykov

Copy link
Copy Markdown
Member

Without this change linker flags set in src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets in SetupOSSpecificProps do not consider tizen platform specifics, which are set in toolchain.cmake.

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jun 25, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

@am11

am11 commented Jun 25, 2026

Copy link
Copy Markdown
Member

Looks good. Is it for cross-publish only or does it work on Tizen machine as well (assuming SDK works on Tizen)?

@gbalykov

Copy link
Copy Markdown
Member Author

Is it for cross-publish only or does it work on Tizen machine as well (assuming SDK works on Tizen)?

Currently I'm checking cross build case. CrossCompileArch is used for cross/native builds check in src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets, however, CrossCompileArch is only set if _hostArchitecture != _targetArchitecture. This is not true for cross build to tizen x64, that's why there's no such check in this patch.


<!-- Tizen requires additional linker args -->
<LinkerArg Include="-B&quot;$(_TizenToolchainPath)&quot;" Condition="'$(_IsTizenExitCode)' == '0'" />
<LinkerArg Include="-L&quot;$(SysRoot)/$(_TizenToolchainLibDir)&quot;" Condition="'$(_IsTizenExitCode)' == '0'" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these things really necessary? We have not been passing standard library paths in other platforms. We pass --sysroot which should set these things up.

@am11 am11 Jun 25, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these maybe necessary, since Tizen might not be using regular/defacto locations in some cases (clang defines them at: https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/Gnu.cpp). @gbalykov, could you please try removing a line, then publish an app on armv7l, arm64 and x64 to see if that line was needed; rinse and repeat to minimize this patch? Typically we only need a few linker related args not everything which was needed to build runtime repo.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've minimized the patch keeping only what's required. Checked this on runtime build, no issues. Sysroot is passed even without this change, but that's not enough.

Without this change linker flags set in src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
in SetupOSSpecificProps do not consider tizen platform specifics, which are set in toolchain.cmake.
@gbalykov gbalykov force-pushed the fix-tizen-link-args branch from cb38d60 to 5460876 Compare June 26, 2026 14:58
@MichalStrehovsky

Copy link
Copy Markdown
Member

Currently I'm checking cross build case. CrossCompileArch is used for cross/native builds check in src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets, however, CrossCompileArch is only set if _hostArchitecture != _targetArchitecture. This is not true for cross build to tizen x64, that's why there's no such check in this patch.

Re-reading this part, are you saying that it's only tizen x64 that has the problem and this is because we don't set CrossCompileArch (the TargetTriple property ends up being empty and we're not passing

<LinkerArg Include="--target=$(TargetTriple)" Condition="'$(TargetTriple)' != ''" Shim="true" />

If so, does adding --target fix this? The lib/lib64 directories are pretty standard and I'm surprised clang wouldn't be setting up the linker correctly if --target is passed. If that's the case, the fix would be around how we decide whether TargetTriple is needed.

@am11

am11 commented Jun 29, 2026

Copy link
Copy Markdown
Member

Cross-compiling linux-musl-x64, openbsd-x64 or freebsd-x64 on linux-x64 would infer cross build based on composite "target and host OS + arch combination are not same". Tizen is odd one out because we decided to identify. I don't think what we have in main is flawed, but rather, it's either:

  1. our calling "tizen" a "linux" is wrong because it's structurally different
  2. or we are confused that "tizen" is structurally different when it's not (it's just another distro with glibc)

If it's 2, then we shouldn't detect distros. There are over 600 linux distros and we will end up maintaining the database here. Best to figure out why we think tizen needs a different flag.

If it's 1. then we should just support tizen-x64 RID and treat it like linux-musl-x64, linux-bionic-x64 (while tizen is glibc based it's structurally different or different in "other ways").

@MichalStrehovsky

Copy link
Copy Markdown
Member

Cross-compiling linux-musl-x64, openbsd-x64 or freebsd-x64 on linux-x64 would infer cross build based on composite "target and host OS + arch combination are not same"

What I wonder is if SysRoot being provided should contribute to the decision about whether this is a crosscompilation.

E.g. what if we updated this line to also check if a SysRoot was provided:

<CrossCompileRid Condition="'$(_hostOS)' != '$(_originalTargetOS)' or '$(_hostArchitecture)' != '$(_targetArchitecture)'">$(RuntimeIdentifier)</CrossCompileRid>

@am11

am11 commented Jun 29, 2026

Copy link
Copy Markdown
Member

In our engineering infra (to build runtime), we set <SysRoot based on CrossBuild. There are two types of cross builds, one which use ROOTFS_DIR infra (like linux, freebsd, illumos, tizen etc.) and then there are those which don't (like osx, ios, android etc.). The latter group infer the cross build implicitly. Long time ago, Jan Vorli brought Android to same plan as the rest of the platforms, but then mono merge overwrote it and we have couple of hacks / weird conditions to make it work.

In BuildIntegration, we can make it all pinned to Sysroot and update these as well:

eng/common/native/LocateNativeCompiler.targets:      <SysRoot Condition="'$(CrossBuild)' == 'true'">$(ROOTFS_DIR)</SysRoot>
eng/targetingpacks.targets:    <SysRoot Condition="('$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)') and '$(HostOS)' != 'windows'">$(ROOTFS_DIR)</SysRoot>

(needs testing)

TL;DR, it is not straight-forward CrossBuild=>Sysroot currently, but it can be done.

@gbalykov

Copy link
Copy Markdown
Member Author

Re-reading this part, are you saying that it's only tizen x64 that has the problem

Yes, only x64 tizen build has this problem. However, adding --target=x86_64-linux-gnu doesn't help, error is still the same.

Initially I also thought whether cross compilation can just be set based on presence of SysRoot, but decided to not do this since it will affect other platforms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-NativeAOT-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants